package cn.jinjimi.app.managers;

import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.content.Context;

import cn.jinjimi.base.util.LogUtil;
import cn.jinjimi.app.AppContext;

import java.util.List;

import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;

/**
 * Created by long on 14-12-29.
 */
public class TaskManager {


    private static class SingelHelper {
        public static TaskManager instance = new TaskManager();
    }

    private TaskManager() {
    }


    public static boolean isBackgroundRunning() {
        String processName = "cn.jinjimi.sixapp";

        ActivityManager activityManager = (ActivityManager) AppContext.getInstance().getSystemService(Context.ACTIVITY_SERVICE);

        if (activityManager == null) return false;
        // get running application processes
        List<ActivityManager.RunningAppProcessInfo> processList = activityManager.getRunningAppProcesses();

        LogUtil.d("TASK Manager", "size" + processList.size());

        if (processList == null)
            return false;

        for (ActivityManager.RunningAppProcessInfo process : processList) {
            if (process.processName.startsWith(processName)) {
                return process.importance != IMPORTANCE_FOREGROUND && process.importance != IMPORTANCE_VISIBLE;
            }
        }
        return false;
    }

    public static boolean isScreeLock(Context context) {
//        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//        boolean isScreenOn = pm.isScreenOn();//如果为true，则表示屏幕“亮”了，否则屏幕“暗”了。
//        return isScreenOn;
        android.app.KeyguardManager mKeyguardManager = (KeyguardManager) context.getSystemService(context.KEYGUARD_SERVICE);
        return mKeyguardManager.inKeyguardRestrictedInputMode();
    }
}
